package com.zyg.demo.entity;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.support.v7.widget.RecyclerView;

import com.zyg.demo.listener.AnimatorListener;

/**
 * @author zhengyunguang
 * created at 2019-07-10 17:36
 */
public class SubPluginShowItem extends AnimItem {

    private ObjectAnimator animator;

    protected AnimatorListener animatorListener;

    public SubPluginShowItem(int pos) {
        super(pos);
        animator = ObjectAnimator.ofFloat(this, "scale", 0, 1f);
    }

    public void setAnimatorListener(AnimatorListener animatorListener) {
        this.animatorListener = animatorListener;
    }

    public void start() {
        animator.setDuration(300);
        animator.setAutoCancel(true);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if(animatorListener != null){
                    animatorListener.onAnimatorUpdate(animation);
                }
            }
        });
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if(animatorListener != null){
                    animatorListener.onAnimatorFinish();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator.start();
    }
}
